package com.iweb.service;

import com.common.datasource.DataSourceUtil;
import com.common.model.DataGrid;
import com.iweb.dao.TravelDao;
import com.iweb.dao.TravelDaoImpl;
import com.iweb.pojo.Travel;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

public class TravelService {
    public List<Travel> selectTravelSite(String title) {

        List<Travel> travels = new ArrayList<>();

        // 链接数据库
        DataSourceUtil dataSourceUtil = new DataSourceUtil();
        dataSourceUtil.init();
        // 创建数据库操作对象
        TravelDao travelDao = new TravelDaoImpl(dataSourceUtil.getConnection());

        try{
            //查找旅游团
            travels = travelDao.selectSite(title);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            dataSourceUtil.close();
        }
        return travels;
    }

    public Travel selectById(String id) {
        Travel travel =null;
        // 链接数据库
        DataSourceUtil dataSourceUtil = new DataSourceUtil();
        dataSourceUtil.init();
        // 创建数据库操作对象
        TravelDao travelDao = new TravelDaoImpl(dataSourceUtil.getConnection());

        try{
            travel = travelDao.findById(id);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            dataSourceUtil.close();
        }
        return travel;
    }

    public  List<Travel> findAllTravel() {
        List<Travel> list = new ArrayList<>();
        // 链接数据库
        DataSourceUtil dataSourceUtil = new DataSourceUtil();
        dataSourceUtil.init();
        // 创建数据库操作对象
        TravelDao travelDao = new TravelDaoImpl(dataSourceUtil.getConnection());

        try{
           list = travelDao.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            dataSourceUtil.close();
        }
        return list ;
    }
}
